<!--
 * @Author: your name
 * @Date: 2020-02-25 13:32:39
 * @LastEditTime: 2020-03-19 13:47:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \福路德扫码系统\html\cksm.html
 -->
<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>Hello APP</title>
	<link rel="stylesheet" type="text/css" href="../css/vant.css">
	<link rel="stylesheet" type="text/css" href="../css/base.css" />
	<link rel="stylesheet" type="text/css" href="../css/local.css" />
	<script type="text/javascript" src="../script/jquery.js"></script>
	<script type="text/javascript" src="../script/echarts.js"></script>
	<script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
	<script type="text/javascript" src="../script/vue.min.js"></script>
	<script type="text/javascript" src="../script/vant.min.js"></script>
	<script type="text/javascript" src="../script/fastclick.js"></script>
	<script type="text/javascript" src="../script/base.js"></script>
	<script type="text/javascript" src="../script/app-tree.js"></script>
	<style type="text/css">
		.part {
			padding: 15px 15px 0 15px;
		}

		.part .pf {
			border-radius: 6px;
			box-shadow: 0px 1px 5px rgb(200, 198, 198);
			background-color: #fff;
			overflow: hidden;
			padding: 4px 0;
		}

		.textarea {
			display: block;
		}

		.label {
			padding: 10px 16px;
			width: 100%;
		}

		.ap-f {
			border-bottom: 1px solid #f7f7f7;
		}

		.f-r {
			/* padding: 17px 0; */
		}

		.mark {
			padding: 17px 15px;
		}

		.mark1 {
			padding: 17px 5px 17px 15px;
			position: relative;
		}

		.f-sub {
			color: #969799;
			font-size: 13px;
			margin-top: 4px;
		}

		.line {
			position: relative;
			width: 30px;
		}

		.line1 {
			width: 60px;
		}

		.line-sq {
			display: inline-block;
			width: 11px;
			height: 11px;
			border-radius: 6px;
			background: #d6d6d6;
			position: absolute;
			left: 0;
			top: 12px;
		}

		.line-li {
			display: inline-block;
			width: 1px;
			background: #d6d6d6;
			position: absolute;
			left: 5px;
			top: -17px;
			bottom: -17px;
		}

		.line-li1 {
			display: inline-block;
			background: #d6d6d6;
			position: absolute;
			top: 52px;
			left: 35px;
			width: 3px;
			bottom: 10px;
		}

		.pd {
			padding: 16px 0;
		}

		.ap-r {
			text-align: right;
			padding-right: 10px;
			/* margin: -8px 0; */
			padding-top: 10px;
		}

		.ap-d {
			text-align: right;
			padding-right: 10px;
			color: #ccccce;
			font-size: 13px;
			float: right;
			padding-top: 3px;
		}

		.img {
			width: 34px;
			height: 34px;
			line-height: 34px;
			text-align: center;
			font-size: 12px;
			color: #fff;
			background-color: #3396fb;
			border-radius: 6px;
			margin: 0 auto;
			position: relative;
			user-select: none;
		}

		.img1 {
			width: 44px;
			height: 44px;
			line-height: 44px;
			text-align: center;
			font-size: 13px;
			color: #fff;
			background-color: #3396fb;
			border-radius: 6px;
			position: relative;
			user-select: none;
		}

		.dis-ib {
			display: inline-block;
			vertical-align: middle;
			text-align: center;
			min-width: 40px;
		}

		.dis2-ib {
			display: inline-block;
			vertical-align: middle;
			padding-bottom: 3px;
			text-align: center;
		}

		.dis3-ib {
			display: inline-block;
			margin: 0 6px;
			color: #969799;
			vertical-align: top;
			padding-top: 7px;
			text-align: center;
		}

		.ap-n {
			padding-top: 2px;
			font-size: 13px;
			color: #969799;
			text-align: center;
		}

		.bottom {
			padding: 8px 15px;
		}

		.part-white {
			padding: 15px;
			background-color: #fff;
			position: relative;
		}

		.title {
			line-height: 40px;
			font-size: 18px;
		}

		.title-sub {
			color: #aaacac;
			font-size: 13px;
		}

		.title-read {
			color: #3396fb;
			font-size: 13px;

		}

		.title-unread {
			color: #788a8a;
			font-size: 13px;
		}

		.ap-res {
			color: #a3a3a3;
			font-size: 15px;
			padding-top: 6px;
		}

		.ap-res1 {
			color: #c31616;
			font-size: 15px;
			padding-top: 6px;
		}

		.ap-img {
			position: absolute;
			right: 20px;
			bottom: -38px;
			width: 88px;
			opacity: 0.4;
		}

		.form-row {
			padding: 4px 16px;
		}

		.form-label {
			color: #808991;
			font-size: 13px;
			user-select: none;
		}

		.color-no {
			color: #808991;
		}

		.form-content {
			padding-top: 5px;
		}

		.npd {
			padding-top: 0;
			overflow-x: auto;
		}

		.pl {
			color: #969799;
			font-size: 16px;
			margin: 6px 2px 18px 0;
			min-height: 25px;
			border-bottom: 1px solid #ebedf0;
		}

		.sf {
			width: 16px;
			background: #fff;
			padding: 2px;
			border-radius: 8px;
			position: absolute;
			right: -5px;
			bottom: -2px;
		}

		.select {
			color: #3396fb;
			float: right;
			font-size: 13px;
			padding-top: 3px;
			vertical-align: middle;
		}

		.select a {
			vertical-align: middle;
		}

		.select img {
			width: 16px;
			vertical-align: middle;
		}

		.hq {
			padding: 10px 10px 0 0;
		}

		.wh {

			white-space: nowrap;
			overflow-x: auto;
			padding-right: 10px;
		}

		.plpd {
			padding-bottom: 5px;
		}

		.pictitle {
			line-height: 24px;
			color: #646566;
			user-select: none;
		}

		.piccontent {
			padding-top: 10px;
			overflow: hidden;
		}

		.van-uploader__preview {
			margin-right: 15px;
		}

		.no {
			text-align: center;
			color: #808991;
			font-size: 14px;
		}

		.li1 {
			top: 15px;
		}

		.li2 {
			bottom: 24px;
		}

		.da-c {
			color: #c31616;
		}

		.danger .van-field__control {
			color: #c31616;
		}

		.danger .van-field__label {
			color: #808991;
		}

		.ac-1 {
			color: #03b553;
		}

		.ac-2 {
			color: #c31616;
		}

		.checkbox {
			padding: 25px 5px 10px 10px;
		}

		.jl-remark {
			padding: 5px 0;
			color: #3396fb;
		}

		.memo-l {
			border-bottom: 1px solid rgb(235, 237, 240);
			padding: 4px 0;
		}

		.memo-l:last-child {
			border-bottom: 0;
		}

		.qd-title {
			font-size: 17px;
			white-space: nowrap;
			text-overflow: ellipsis;
			overflow: hidden;
			word-break: break-all;
			padding-right: 10px;
		}

		.date {
			float: right;
			font-size: 12px;
			color: #cbcbcb;
		}

		.sub {
			white-space: nowrap;
			text-overflow: ellipsis;
			overflow: hidden;
			word-break: break-all;
			font-size: 14px;
			color: #a3a3a3;
		}

		.creater {
			font-size: 14px;
		}

		.sq {
			display: inline-block;
			font-size: 13px;
			margin: 2px 8px 0 0;
			margin-right: 8px;
			min-width: 16px;
			height: 18px;
			line-height: 18px;
			border-radius: 4px;
			text-align: center;
			background-color: #3396fb;
			color: #ffffff;
		}

		.qd-title span {
			vertical-align: middle;
		}

		.fc-1 {
			color: #3396fb;
			font-weight: 700;
		}

		.fc-2 {
			color: #ee0a24;
			font-weight: 700;
		}

		.arrow {
			padding: 4px 0;
		}

		.arrowup {
			padding: 8px 0;
			color: #3396fb;
			text-align: center;
			font-size: 14px;
		}

		.label .squ {
			background: #3775ff;
			width: 5px;
			height: 16px;
			display: inline-block;
			border-radius: 2px;
			margin-top: 5px;
			margin-right: 8px;
		}

		.chart {
			width: 100%;
			height: 200px;
			background-color: #f7f8fa;
			border-radius: 8px;
		}


		.van-tabs {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 0;
			background: #fff;
			z-index: 99;
			transition: all 0.4s;
			opacity: 0;

		}

		.van-tabs__wrap {
			padding-bottom: 5px;
		}

		.bg {
			height: 44px;
			opacity: 1;
		}

		.total-num {
			width: 60px;
			text-align: right;
		}

		.sq-1 {
			color: #3775ff;
		}

		.bg-t {
			color: #3396fb;
		}

		.totalHead {
			font-weight: bold;
			font-size: 15px;
		}

		.totalItem {
			font-size: 14px;
			color: #969799;
		}

		.upArrow {
			color: blue;
		}

		.downArrow {
			color: red;
		}
	</style>
</head>

<body>
	<div id="app" v-cloak>
		<div class="box">
			<van-nav-bar-main :title="form.ApprTitle" left-arrow @click-left="onClickLeft"></van-nav-bar-main>
			<div class="content" style="padding-bottom: 20px;">
				<van-tabs color="#3370ff" v-model="tabIndex" @click="changeTab">
					<van-tab title="业务信息"></van-tab>
					<van-tab title="业务明细"></van-tab>
					<van-tab title="审批进度"></van-tab>
				</van-tabs>
				<div class="content-refresh" onScroll="scrollMove()">
					<div class="sw">
						<div class="part-white">
							<div class="title">{{form.ApplyName}}提交的{{form.ApprTitle}}</div>
							<div class="ap-res">{{finalResult==0?'正在审批中':(finalResult==1?'审批已通过':'审批已拒绝')}}</div>
							<div style="padding-bottom: 10px;"></div>
							<img class="ap-img" v-if="finalResult!=0" :src="'../image/ap-'+ finalResult +'.png'" />
						</div>
					</div>

					<div>
						<div class="part">
							<div class="pf">
								<div class="form-row">
									<div class="form-label">流水单号</div>
									<div class="form-content">{{form.ApprNO}}</div>
								</div>
								<div class="form-row">
									<div class="form-label">审批标题</div>
									<div class="form-content">{{form.ApprTitle}}</div>
								</div>
								<div class="form-row">
									<div class="form-label">审批摘要</div>
									<div class="form-content">{{form.ApprDesc}}</div>
								</div>
								<div class="form-row">
									<div class="form-label">发起人</div>
									<div class="form-content">{{form.ApplyName}}</div>
								</div>
								<div class="form-row">
									<div class="form-label">部门</div>
									<div class="form-content">{{form.Department}}</div>
								</div>
								<div class="form-row">
									<div class="form-label">发起时间</div>
									<div class="form-content">{{form.ApplyTime}}</div>
								</div>
								<div class="form-row">
									<div class="form-label">单据类型</div>
									<div class="form-content">{{form.BizType}}</div>
								</div>
								<div class="form-row">
									<div class="form-label">单据编号</div>
									<div class="form-content">{{form.BizNO}}</div>
								</div>
								<div class="form-row">
									<div class="form-label">单据备注</div>
									<div class="form-content">{{form.BizRemark}}</div>
								</div>
								<!-- 业务主表 -->
								<div class="form-row" v-for="(value,key) in form.bizMainData[0]" :key="key">
									<div class="form-label">{{ key }}</div>
									<div class="form-content">{{ value }}</div>
								</div>
							</div>
						</div>
					</div>

					<!-- 业务明细 -->
					<div class="sp" v-if="form.bizDetailData.length">
						<div class="part">
							<div class="pf">
								<div class="label flex-box">
									<div class="squ"></div>
									<div class="flex-main">业务明细</div>
								</div>
								<div>
									<van-cell v-for="(row,index) in form.bizDetailData" :key="index">
										<div>
											<div class="flex-box">
												<div class="sq">{{index + 1}}</div>
												<div class="flex-main">
													<!-- <div class="bg-t"> -->
														<van-row v-for="(value,key) in row" :key="key">
															<van-col span="6">
																<strong>{{ key }}</strong>
															</van-col>
															<van-col span="18">
																<span>{{ value }}</span>
															</van-col>
														</van-row>
													<!-- </div> -->
												</div>
											</div>
										</div>
									</van-cell>
									<!-- <van-cell v-for="(row,index) in form.list1">
									<div>
										<div class="flex-box">
											<div class="sq">{{index + 1}}</div>
											<div class="flex-main">
												<div class="bg-t">
													<van-row>
														<van-col span="24">
															<div>{{row.CinvCName}}/{{row.cInvCode}}/{{row.cInvName}}
															</div>
														</van-col>
														<van-col span="12">
															<div>总数量：{{row.total}}</div>
														</van-col>
														<van-col span="12">
															<div>无税总金额：{{row.money.toFixed(2)}}</div>
														</van-col>
													</van-row>
												</div>

											</div>
										</div>
										<div>
											<div class="chart" :id="'chart' + index"></div>
										</div>
										<div style="margin-left: -8px;">
											<van-row>
												<van-col span="24">
													<div v-for="(item,itemIndex) in row.node">
														<div class="flex-box">
															<div class="sq-1">【{{(index + 1) + '-' + (itemIndex +
																1)}}】</div>
															<div class="flex-main">
																<van-row>
																	<van-col span="12">
																		<div class="sub">请购部门：{{item.ClassName}}
																		</div>
																	</van-col>
																	<van-col span="12">
																		<div class="sub">申请人员：{{item.EmplName}}
																		</div>
																	</van-col>
																	<van-col span="12">
																		<div class="sub">采购数量：{{item.Quantity}}
																		</div>
																	</van-col>
																	<van-col span="24">
																		<div class="sub">
																			需求日期：{{item.NeedDate?item.NeedDate.split('T')[0]:''}}
																		</div>
																	</van-col>
																	<van-col span="12">
																		<div class="sub">无税单价：{{item.Evaluation}}
																		</div>
																	</van-col>
																	<van-col span="12">
																		<div class="sub">
																			无税金额：{{(item.Evaluation*item.Quantity).toFixed(2)}}
																		</div>
																	</van-col>
																	<van-col span="24" v-if="item.FRemarks">
																		<div class="sub">备注：{{item.FRemarks}}</div>
																	</van-col>
																	<van-col span="24">
																		<div class="sub"><b
																				style="color: #000;">当前库存：{{item.cInvCount}}</b>
																		</div>
																	</van-col>
																</van-row>

															</div>
														</div>


													</div>
												</van-col>

											</van-row>



										</div>
									</div>

								</van-cell> -->
								</div>
							</div>
						</div>
					</div>

					<div class="c">
						<div class="part" v-for="approvalRow in approvalList">
							<div class="pf">
								<div class="label">流程</div>
								<div class="pd">
									<div>
										<div class="flex-box f-r">
											<div class="mark1 npd">
												<div class="line1">
													<div>
														<div class="dis-ib">
															<div class="img1"><span>{{creater}}</span><img class="sf"
																	src="../image/success.png" /></div>
														</div>
													</div>
													<div class="line-li1"></div>
												</div>

											</div>
											<div class="flex-main npd">
												<div>
													<div>
														<span>发起审批</span>
														<span class="ap-d"
															v-if="createTime">{{createTime.split('.')[0].replace(/T/g,'')}}</span>
													</div>
													<div class="f-sub">{{creater}}</div>
												</div>
												<div class="pl"></div>
											</div>
										</div>
									</div>
									<div v-for="(row,index) in approvalRow.approvalNodeList">
										<div class="flex-box f-r">
											<div class="mark1 npd">
												<div class="line1">
													<div>
														<div class="dis-ib">
															<div class="img1">
																<span
																	v-if="row.node.length == 1 && row.node[0].CurrentApprovalIDs.length == 1 && row.type == 0">{{row.node[0].CurrentApprovalIDs[0]}}</span>
																<van-icon v-else-if="row.type == 1" name="volume-o"
																	size="28px" style="padding-top: 7px;">
																</van-icon>
																<van-icon v-else name="friends-o" size="28px"
																	style="padding-top: 7px;"></van-icon>
																<img class="sf"
																	v-if="approvalRow.level == row.index - 2 && row.type == 1 && row.node[0].Approve != 0"
																	src="../image/success.png" />
																<img class="sf"
																	v-if="approvalRow.level >= row.index - 1"
																	:src="getApprovalTagImg(row)" />
															</div>
														</div>
													</div>
													<div class="line-li1"
														v-if="index != approvalRow.approvalNodeList.length - 1"></div>
												</div>

											</div>
											<div class="flex-main npd">
												<div>
													<div>
														<div>
															<span style="vertical-align: middle;"
																v-if="row.type == 1">抄送人</span>
															<span style="vertical-align: middle;"
																v-else>{{row.department?row.department:'审批人'}}</span>
															<span>
																<van-icon name="more" color="#afd6ff"
																	style="vertical-align: middle;padding-left: 5px;"
																	@click="showMore(row)"></van-icon>
															</span>
															<span class="ap-d"
																v-if="approvalRow.level == row.index - 2 && row.type == 1 && row.node[0].Approve != 0">{{row.node[0].ApproveTime}}</span>
															<span class="ap-d"
																v-if="approvalRow.level >= row.index - 1">{{row.node[0].ApproveTime}}</span>
														</div>

														<div class="f-sub" v-if="row.showMore">
															<span
																v-if="row.node.length == 1 && row.node[0].CurrentApprovalIDs.length == 1">{{row.node[0].CurrentApprovalIDs[0]}}</span>
															<span
																v-if="row.node.length == 1 && row.node[0].CurrentApprovalIDs.length > 1 && row.type == 0">{{row.node[0].CurrentApprovalIDs.length}}人或签</span>
															<span
																v-if="row.node.length > 1 && row.type == 0">{{row.node.length}}人会签</span>
															<span
																v-if="row.node.length > 1 && !checkIsSingle(row) && row.type == 0">多人审核</span>
															<span
																v-if="approvalRow.level == row.index - 2 && row.type == 1 && row.node[0].Approve != 0">（已抄送）</span>
															<span
																v-if="approvalRow.level >= row.index - 1">（{{getApprovalText(row)}}）</span>
														</div>
													</div>
													<div class="hq" v-if="row.showMore">
														<!-- 或签 -->
														<div class="wh"
															v-if="row.node.length == 1 && row.node[0].CurrentApprovalIDs.length > 1">
															<div class="dis2-ib"
																v-for="(item,itemIndex) in row.node[0].CurrentApprovalIDs">
																<div class="dis-ib">
																	<div class="img">
																		<span>{{cutStr(item)}}</span>
																		<img class="sf"
																			v-if="item == row.node[0].Approver && approvalRow.level >= row.index - 1 && row.node[0].Approve != 0"
																			:src="row.node[0].Approve == 1?'../image/success.png':'../image/fail.png'" />
																	</div>
																	<div class="ap-n">{{item}}</div>
																</div>
																<div class="dis3-ib"
																	v-if="itemIndex != row.node[0].CurrentApprovalIDs.length - 1 && row.type == 0">
																	/</div>
																<div class="dis3-ib" v-if="row.type == 1"> </div>
															</div>

														</div>
														<!-- 会签 -->
														<div class="wh"
															v-if="row.node.length > 1 && checkIsSingle(row)">
															<div class="dis2-ib" v-for="(item,itemIndex) in row.node">
																<div class="dis-ib">
																	<div class="img">
																		<span>{{cutStr(item.CurrentApprovalIDs[0])}}</span>
																		<img class="sf"
																			v-if="item.Approver && item.Approver == item.CurrentApprovalIDs[0] && approvalRow.level >= row.index - 1 && item.Approve != 0"
																			:src="item.Approve == 1?'../image/success.png':'../image/fail.png'" />
																	</div>
																	<div class="ap-n">{{item.CurrentApprovalIDs[0]}}
																	</div>
																</div>
																<div class="dis3-ib"
																	v-if="itemIndex != row.node.length - 1 && row.type == 0">
																	+</div>
																<div class="dis3-ib" v-if="row.type == 1"> </div>
															</div>

														</div>
														<!-- 多人审核 -->
														<div class="wh"
															v-if="row.node.length > 1 && !checkIsSingle(row)">
															<div class="dis2-ib" v-for="(item,itemIndex) in row.node">
																<div class="dis2-ib"
																	v-for="(detail,detailIndex) in item.CurrentApprovalIDs">
																	<div class="dis-ib">
																		<div class="img">
																			<span>{{cutStr(detail)}}</span>
																		</div>
																		<div class="ap-n">{{detail}}
																		</div>
																	</div>
																	<div class="dis3-ib"
																		v-if="itemIndex != row.node.length - 1">/</div>
																</div>
																<div class="dis3-ib"
																	v-if="itemIndex != row.node.length - 1"> </div>
															</div>
														</div>
													</div>
													<div class="pl">
														<div class="plpd" v-for="item in row.node">
															<div>
																<span v-if="item.ApprovalContent"
																	:class="'ac-' + item.Approve">{{item.Approver}}:</span>
																<span v-if="item.ApprovalContent"
																	:class="'ac-' + item.Approve">"{{item.ApprovalContent}}"</span>
															</div>

															<div class="piccontent" v-if="item.Imgs">
																<div class="van-uploader">
																	<div class="van-uploader__wrapper">
																		<div class="van-uploader__preview"
																			v-for="(imgItem,imgItemIndex) in (item.Imgs?item.Imgs.split(','):[])">
																			<div class="van-image van-uploader__preview-image"
																				style="overflow: hidden; border-radius: 4px;width:60px;height:60px;"
																				@click="previewItemImage(item.Imgs,imgItemIndex,3)">

																				<img :src="serverIP + imgItem"
																					class="van-image__img"
																					style="object-fit: cover;" />
																			</div>
																		</div>
																	</div>
																</div>
															</div>

														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>

							</div>
						</div>
					</div>
				</div>


			</div>


			<div class="bottom" v-if="showButton == 1 && status != -1">
				<div class="flex-main">
					<van-row gutter="30">
						<van-col :span="12">
							<van-button type="info" block :square="false" :disabled="ifConfirm" :loading="ifConfirm"
								@click="dealApproval(1)">
								输入审核意见或确认同意</van-button>
						</van-col>
						<van-col :span="12">
							<van-button type="info" block :square="false" :disabled="ifConfirm" :loading="ifConfirm"
								@click="dealApproval(2)">
								拒绝</van-button>
						</van-col>
					</van-row>
				</div>
			</div>

			<div class="bottom"
				v-if="(status == 2 && creater == userData.UserName && finalResult == 2) || approvalAgain">
				<div class="flex-main">
					<van-row gutter="30">
						<van-col :span="24">
							<van-button type="info" block :square="false" :disabled="ifConfirm" :loading="ifConfirm"
								@click="initiateApprovalAgain">再次提交评审</van-button>
						</van-col>
					</van-row>
				</div>
			</div>
		</div>

		<van-action-sheet v-model="showProcedureAction" :actions="procedureActions" cancel-text="取消" description="请选择工序"
			close-on-click-action @select="confirmProcedureAction"></van-action-sheet>
	</div>
</body>
<script type="text/javascript">
	var isSLS = false;
	function scrollMove() {
		if (isSLS) return;
		if ($('.content-refresh').scrollTop() > 40) {
			$('.van-tabs').addClass('bg')
		} else {
			$('.van-tabs').removeClass('bg')
		}

		if ($('.content-refresh').scrollTop() < $('.sp').offset().top - $('.sw').offset().top - 40) {
			vm.tabIndex = 0;
		}
		if ($('.sp').offset().top - $('.sw').offset().top - 40 < $('.content-refresh').scrollTop() && $('.content-refresh').scrollTop() < $('.c').offset().top - $('.sw').offset().top - 40) {
			vm.tabIndex = 1;
		}
		if ($('.content-refresh').scrollTop() > $('.c').offset().top - $('.sw').offset().top - 40) {
			vm.tabIndex = 2;
		}
	}

	var vm;
	apiready = function () {
		var UIAlbumBrowser = api.require('UIAlbumBrowser');
		var photoBrowser = api.require('photoBrowser');
		var isOpenImg = false;
		var approvalConfigdata = '';
		var allCurrentApprovalIDs = [];

		api.addEventListener({
			name: 'keyback'
		}, function (ret, err) {
			if (!isOpenImg) {
				vm.onClickLeft();
			} else {
				photoBrowser.close();
			}

		});

		api.addEventListener({
			name: 'submitApproval'
		}, function (ret, err) {
			var index = ret.value.index;
			var content = ret.value.content;
			var imgArray = ret.value.imgArray;
			var reworkDepart = ret.value.reworkDepart;
			if (vm.status == 0 || vm.status == 2) {
				vm.startApproval(index, content);
			} else {
				vm.submitApproval(index, content, imgArray, reworkDepart);


			}

		});

		api.addEventListener({
			name: 'submitRemark'
		}, function (ret, err) {
			var content = ret.value.content;
			var imgArray = ret.value.imgArray;
			var userids = [];
			for (var i in allCurrentApprovalIDs) {
				if (userids.indexOf(allCurrentApprovalIDs[i]) == -1) {
					userids.push(allCurrentApprovalIDs[i])
				}
			}
			var obj = {
				Ck_ReviewID: vm.form.id,
				FRemarks: content,
				MemoImg: imgArray.join(),
				MsgUserIDs: userids.join()
			}
			APP.ajax('updateCkReviewRemarks', obj, function (res) {
				layer.open({
					content: '备注添加成功',
					skin: 'msg',
					time: 2
				});
				APP.ajax('getCkReviewByID', { Ck_ReviewID: vm.form.id }, function (res) {
					if (res.ds.length) {
						vm.form.memo = res.ds[0].Memo;
						vm.form.memoImg = res.ds[0].MemoImg ? res.ds[0].MemoImg.split(',') : [];
					}
				})
			})
		});

		api.addEventListener({
			name: 'selectRow'
		}, function (ret, err) {
			var type = ret.value.type;
			var row = ret.value.row;
			if (type == '产品') {
				vm.form.pid = row[0].ProductID;
				vm.form.pname = row[0].ProductName;
				vm.form.pcode = row[0].ProductCode;
			}
			if (type == '人员') {
				vm.form.personname = row[0].UserName;
				vm.form.personid = row[0].UserID;
				vm.form.persondepartname = row[0].ClassName || '';
				vm.form.persondepartid = row[0].ClassID || 0;
			}
		})

		var chartData = [];


		vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				ifConfirm: false,
				serverIP: 'http://' + APP.serverIP(),
				userData: APP.getUserInfo(),
				showButton: 0,
				isSubmit: false,
				personList: [],
				approvalAgain: false,

				showProcedureAction: false,
				procedureActions: [{
					name: '品质'
				}, {
					name: '包装'
				}, {
					name: '注塑'
				}, {
					name: '电镀'
				}, {
					name: '喷漆'
				}, {
					name: '装配'
				}, {
					name: 'FQC'
				}, {
					name: '蚀刻'
				}],
				showAction: false,
				approvalActions: [],
				selectApprovalData: '',
				approvalList: [],
				approvalProcessList: [],
				status: -1,
				creater: '',
				createTime: '',
				approvalID: 0,
				approveStr: '',
				level: 0,
				finalResult: 0,
				readArray: [],
				// unReadArray: [],
				arrowStatus1: false,
				arrowStatus2: false,
				arrowStatus3: false,
				form: {
					id: api.pageParam.id,
					ApplyName: '',	//发起人
					ApplyTime: '',	//发起时间
					Department: '',	//发起部门
					ApprNO: '',	//审批记录流水号
					ApprTitle: '',	//审批标题
					ApprDesc: '',	//审批摘要
					BizType: '',
					BizNO: '',
					BizRemark: '',
					Type: '',
					FRemarks: '',
					bizMainData: [],
					bizDetailData: []
				},
				timeout: 15,
				editRemark: true,
				tabIndex: 0
			},
			created: function () {
				var that = this;

				APP.ajax('getApproveModel', {}, function (res) {
					var approvalActions = [];
					for (var i in res.ds) {
						if (res.ds[i].AppFormName == 'approvalPage1') {
							res.ds[i].name = res.ds[i].BillName;
							approvalActions.push(res.ds[i])
						}
					}
					that.approvalActions = approvalActions;


					APP.ajax('getCkUserList', {}, function (res) {

						that.personList = res.ds;

						if (that.form.id) {
							that.checkIsShowButton();
							that.initPageData();
						} else {
							that.status = 0;
						}
					})
				})

			},
			methods: {

				post: function (sql, param, callBack) {
					//
					var that = this;
					param["sql"] = sql;
					$.ajax({
						url: "http://" + APP.serverIP() + "/SQLData/QuerySql",
						type: "post",
						dataType: "json",
						async: false,
						data: param,
						success: function (data) {
							if (data.status == 200) {
								callBack(data.data);
							} else {
								alert(data.msg)
							}
						}
					});
				},
				changeTab(name, title) {
					var that = this;
					isSLS = true;
					if (that.tabIndex == 0) {
						$('.content-refresh').animate({ scrollTop: '0px' }, 600, function () {
							setTimeout(function () {
								isSLS = false;
								$('.van-tabs').removeClass('bg');
							}, 100)

						})
					} else if (that.tabIndex == 1) {
						$('.content-refresh').animate({ scrollTop: ($('.sp').offset().top - $('.sw').offset().top - 40) + 'px' }, 600, function () {
							setTimeout(function () {
								isSLS = false;
							}, 100)
						});
					} else if (that.tabIndex == 2) {
						$('.content-refresh').animate({ scrollTop: ($('.c').offset().top - $('.sw').offset().top - 40) + 'px' }, 600, function () {
							setTimeout(function () {
								isSLS = false;
							}, 100)
						});
					}


				},
				toggleArrow(str) {
					var that = this;
					that[str] = !that[str];
				},
				getRealNum: function (row) {
					var that = this;
					var t = 0;
					for (var i in row.node) {
						if (!row.node[i].unJoin) {
							t++;
						}
					}
					return t;
				},
				toggleUserCheck: function (row, item) {
					var that = this;
					if (typeof item.unJoin === 'undefined') {
						that.$set(item, 'unJoin', true);
						var x = 1;
						for (var i in row.node) {
							if (!row.node[i].unJoin) {
								x = 0;
							}
						}
						if (x == 1) {
							layer.open({
								content: '请至少选择一人',
								skin: 'msg',
								time: 2
							});
							that.$set(item, 'unJoin', false);
						}
					} else {
						that.$set(item, 'unJoin', !item.unJoin);
						// item.unJoin = !item.unJoin;
						// alert(item.unJoin)
						var x = 1;
						for (var i in row.node) {
							if (!row.node[i].unJoin) {
								x = 0;
							}
						}
						if (x == 1) {
							layer.open({
								content: '请至少选择一人',
								skin: 'msg',
								time: 2
							});
							item.unJoin = !item.unJoin;
						}

					}

				},
				showMore: function (row) {
					var that = this;
					if (row.showMore) {
						that.$set(row, 'showMore', false);
					} else {
						that.$set(row, 'showMore', true);
					}

				},
				getApprovalProcess: function (id) {
					var that = this;
					function recursionFunc(data) {
						var approvalProcessList = [];
						var repeatConfig = function (x, row) {
							var processData = {
								type: row.type,
								approvalType: row.examineMode == 1 ? 0 : 1,
								nodeName: row.nodeName,
								node: [],
								checked: false,
								data: row
							}
							if (row.settype == 7) {
								processData.node.push({
									name: row.examineEndDirectorLevel + '级主管'
								})
							} else {
								processData.node = row.nodeUserList;
							}
							approvalProcessList.push(processData)
							if (row.childNode) {
								repeatConfig(x + 1, row.childNode);
							}
						}
						if (data && data.nodeConfig) {
							repeatConfig(0, data.nodeConfig.childNode);
						}
						return approvalProcessList;
					}

					APP.ajax('GetApproveByID', { APFlowID: id }, function (res) {
						approvalConfigdata = JSON.parse(res.ds[0].AppConfigStr);

						// if (that.isExamine == 2) {
						var approvalProcessList = recursionFunc(approvalConfigdata);
						var newApprovalProcessList = [];
						if (that.approveStr) {
							newApprovalProcessList = recursionFunc(JSON.parse(that.approveStr));
						}
						for (var i in approvalProcessList) {
							var w = 0;
							for (var j in newApprovalProcessList) {
								if (approvalProcessList[i].nodeName == newApprovalProcessList[j].nodeName) {
									w = 1
									approvalProcessList[i].checked = true;

									for (var m in approvalProcessList[i].node) {
										var v = 0;
										for (var n in newApprovalProcessList[j].node) {
											if (approvalProcessList[i].node[m].name == newApprovalProcessList[j].node[n].name) {
												v = 1;
												approvalProcessList[i].node[m].unJoin = false;
											}
										}
										if (!v) {
											approvalProcessList[i].node[m].unJoin = true;
										}
									}

								}
							}
							if (!w && newApprovalProcessList.length) {
								approvalProcessList[i].checked = false;
							}
						}
						that.approvalProcessList = approvalProcessList;

					})



				},
				previewItemImage: function (imgs, index) {
					var that = this;
					var array = imgs.split(',');
					for (var i in array) {
						array[i] = that.serverIP + array[i];
					}
					photoBrowser.open({
						images: array,
						activeIndex: index,
						bgColor: '#000'
					}, function (ret) {
						isOpenImg = true;
						if (ret) {
							if (ret.eventType == 'click') {
								isOpenImg = false;
								photoBrowser.close();
							}
						}
					})
				},
				previewImage: function (index, type) {
					var that = this;
					var array = JSON.parse(JSON.stringify(type == 1 ? that.form.imgArray : that.form.memoImg));
					for (var i in array) {
						array[i] = that.serverIP + array[i];
					}
					photoBrowser.open({
						images: array,
						activeIndex: index,
						bgColor: '#000'
					}, function (ret) {
						isOpenImg = true;
						if (ret) {
							if (ret.eventType == 'click') {
								isOpenImg = false;
								photoBrowser.close();
							}
						}
					})
				},
				deleteImgItem: function (index) {
					var that = this;
					that.form.imgArray.splice(index, 1)
				},
				addImage: function (len) {
					var that = this;
					//
					UIAlbumBrowser.imagePicker({
						max: 15 - len,
						styles: {
							nav: {
								bg: 'rgba(0,0,0,.6)',
								finishText: '完成'
							}
						},
						rotation: true
					}, function (ret) {
						if (ret) {
							if (ret.originalPath) {
								UIAlbumBrowser.transPath({
									path: ret.assetPath || ret.originalPath
								}, function (ret, err) {
									if (ret) {
										APP.uploadFile('审批图片1', ret.path, function (path) {
											that.form.imgArray.push(path);
										})

									}
								});
							} else if (ret.eventType == 'nextStep') {
								UIAlbumBrowser.closePicker();
								var imgLists = ret.list;
								var repeatImg = function (i) {
									if (i == imgLists.length) {
										return;
									}
									UIAlbumBrowser.transPath({
										path: imgLists[i].path
									}, function (ret, err) {
										if (ret) {
											APP.uploadFile('审批图片1', ret.path, function (path) {
												that.form.imgArray.push(path);
											})
											i++;
											repeatImg(i);
										}
									});
								}
								repeatImg(0)

							}

						}
					});
				},
				checkIsShowButton: function () {
					var that = this;
					var obj = {
						P_TableName: 'SYS_GeneralApproval',
						P_PKValue: that.form.id
					}
					APP.ajax('WhetherItCanBeApproved', obj, function (res) {
						that.showButton = res.ds[0].ISSP;
					})
				},
				filterPersonList: function (str, value) {
					var that = this;
					var row = null;
					for (var i in that.personList) {
						if (that.personList[i][str] == value) {
							row = that.personList[i];
							break;
						}
					}
					return row;
				},
				getApprovalTagImg: function (row) {
					var that = this;
					if (row.node.length == 1) {
						if (row.node[0].Approve == 0) {
							return '../image/doing.png';
						} else if (row.node[0].Approve == 1) {
							return '../image/success.png';
						} else if (row.node[0].Approve == 2) {
							return '../image/fail.png';
						}
					} else {

						var imgstr = '';
						var z = 0;
						for (var i in row.node) {
							if (row.node[i].Approve == 1) {
								z++;
							}
							if (row.node[i].Approve == 2) {
								imgstr = '../image/fail.png';
								break;
							}
						}
						if (imgstr) {
							return imgstr;
						} else {
							if (z == 0) {
								imgstr = '../image/doing.png'
							} else {
								if (row.node.length == z) {
									imgstr = '../image/success.png'
								} else {
									imgstr = '../image/doing.png';
								}
							}

						}
						return imgstr;
					}
				},
				getApprovalText: function (row) {
					var that = this;
					if (row.type == 1) {
						if (row.node[0].Approve == 0) {
							return '未抄送';
						} else {
							return '已抄送';
						}
					} else {
						if (row.node.length == 1) {
							if (row.node[0].Approve == 0) {
								return '审批中';
							} else if (row.node[0].Approve == 1) {
								return '已同意';
							} else if (row.node[0].Approve == 2) {
								return '已拒绝';
							}
						} else {
							var str = '';
							var z = 0;
							for (var i in row.node) {
								if (row.node[i].Approve == 1) {
									z++;
								}
								if (row.node[i].Approve == 2) {
									str = '已拒绝';
									break;
								}
							}
							if (str) {
								return str;
							} else {
								if (z == 0) {
									str = '审批中'
								} else {
									if (row.node.length == z) {
										str = '已同意'
									} else {
										str = z + '人同意';
									}
								}

							}
							return str;
						}
					}
				},
				cutStr: function (str) {
					var that = this;
					return str && str.substring(str.length - 2);
				},
				checkIsSingle: function (row) {
					var that = this;
					var x = true;
					for (var i in row.node) {
						if (row.node[i].CurrentApprovalIDs.length > 1) {
							x = false;
						}
					}
					return x;
				},
				setChart: function (row, index) {
					var that = this;
					var myChart = echarts.init(document.getElementById('chart' + index));
					var x = [];
					var y1 = [];
					var y2 = [];
					for (var i in chartData) {
						if (chartData[i].cinvCode == row.cInvCode) {
							x.push(APP.getFormatDate1('yy-MM', new Date(chartData[i].dArriveDate)));
							y1.push(chartData[i].iQuantity);
							y2.push(chartData[i].iUnitPrice);
						}
					}
					var option = {
						title: {
							text: '往期采购趋势',
							textStyle: {
								fontSize: 14
							}

						},
						legend: {
							data: ['采购数量', '采购单价'],
							right: 0
						},
						grid: {
							// top: 30,
							left: 40,
							right: 30,
							bottom: 30
						},
						xAxis: {
							type: 'category',
							name: '',
							data: x
						},
						yAxis: [{
							type: 'value',
							name: '采购数量'
						}, {
							type: 'value',
							name: '采购单价',
							splitLine: {
								show: false
							}
						}],
						series: [{
							data: y1,
							type: 'bar',
							barWidth: 12,
							label: {
								show: true
							},
							name: '采购数量'
						}, {
							data: y2,
							type: 'line',
							yAxisIndex: 1,
							name: '采购单价',
							label: {
								show: true
							},
							smooth: true
						}]
					};
					myChart.setOption(option);
				},
				initPageData: function () {
					var that = this;
					var obj1 = {
						GenApprID: that.form.id
					}
					APP.ajax('getGenApprDetail', obj1, function (res) {
						console.log(JSON.stringify(res))

						if (res.ds.length) {
							// 1.审批记录主体信息
							that.form.ApprNO = res.ds[0].ApprNO;
							that.form.ApprTitle = res.ds[0].ApprTitle;
							that.form.ApprDesc = res.ds[0].ApprDesc;

							that.form.Department = res.ds[0].Department;
							that.form.ApplyName = res.ds[0].ApplyName;
							that.form.ApplyTime = res.ds[0].ApplyTime;
							that.form.Department = res.ds[0].Department;

							that.form.BizType = res.ds[0].BizType;
							that.form.BizNO = res.ds[0].BizNO;
							that.form.BizRemark = res.ds[0].BizRemark;

							that.creater = res.ds[0].Creater;
							that.createTime = res.ds[0].CreateTime;
							that.status = res.ds[0].Status;
							that.approvalID = res.ds[0].APFlowID;

							// 2.业务信息
							that.form.bizMainData = res.ds1;

							// 3.业务明细
							that.form.bizDetailData = res.ds2;

							if (that.status == 0) {
								//获取审批流配置列表
								if (that.approvalID) {
									that.approvalID && that.getApprovalProcess(that.approvalID);
								} else {
									if (that.approvalActions.length) {
										that.getApprovalProcess(that.approvalActions[0].APFlowID)
									}
								}
							} else {
								var obj2 = {
									P_PKValue: that.form.id,
									P_TableName: 'SYS_GeneralApproval'
								}
								APP.ajax('Select_FlowLog1', obj2, function (res) {

									if (!res.ds.length) {
										that.approvalList = [];
										return;
									}

									if (res.ds[res.ds.length - 1].Approve == 1) {
										that.finalResult = 1;
									}

									var data = [];
									allCurrentApprovalIDs = [];
									var allCurrentApprovalIDs2 = [];
									for (var i in res.ds) {
										res.ds[i].CurrentApprovalIDs = res.ds[i].CurrentApprovalIDs.replace(/^,+/, "").replace(/,+$/, "").split(',');

										allCurrentApprovalIDs = allCurrentApprovalIDs.concat(res.ds[i].CurrentApprovalIDs);
										if (res.ds[i].FlowType != 1) {
											allCurrentApprovalIDs2 = allCurrentApprovalIDs2.concat(res.ds[i].CurrentApprovalIDs);
										}
										for (var c in res.ds[i].CurrentApprovalIDs) {
											var row = that.filterPersonList('UserID', res.ds[i].CurrentApprovalIDs[c])
											if (row) {
												res.ds[i].CurrentApprovalIDs[c] = row.UserName;
											}

										}

										if (data.indexOf(res.ds[i].AuditID) == -1) {
											data.push(res.ds[i].AuditID);
										}
									}

									var approvalList = [];
									for (var n in data) {
										var approvalNodeList = [];
										var level = 0;
										var finLevel = 0;
										for (var i in res.ds) {
											if (data[n] == res.ds[i].AuditID) {

												if (res.ds[i].Approve == 0 && !level) {
													level = res.ds[i].ApprovalSort;
												}

												if (res.ds[i].Approve == 1 && i == res.ds.length - 1) {
													level = res.ds[i].ApprovalSort;
												}

												if (res.ds[i].Approve == 2 && !finLevel) {
													finLevel = res.ds[i].ApprovalSort;
												}


												if (res.ds[i].Approve == 2 && n == data.length - 1) {
													that.finalResult = 2;
												}



												var x = 0;
												for (var j in approvalNodeList) {
													if (approvalNodeList[j].index == res.ds[i].ApprovalSort) {
														x = 1;
														approvalNodeList[j].node.push(res.ds[i]);
													}
												}
												if (!x) {
													approvalNodeList.push({
														index: res.ds[i].ApprovalSort,
														type: res.ds[i].FlowType,
														department: res.ds[i].ApprovalName,
														node: [res.ds[i]]
													})
												}
											}

										}
										approvalList.push({
											level: finLevel ? (finLevel - 1) : (level - 1),
											approvalNodeList: approvalNodeList
										})
									}


									var p1 = 0;
									var y = 0;
									if (that.finalResult == 1) {
										for (var i in res.ds) {
											if (res.ds[i].Approver && res.ds[i].FlowType != 1) {
												p1++;
												if (res.ds[i].Approver == that.userData.UserName) {
													y = 1;

												}
											}

										}

										// APP.ajax('getReadUserList', { Ck_ReviewID: that.form.id }, function (res1) {

										// 	that.readArray = res1.ds;
										// 	var unReadArray = [];
										// 	for (var m in res.ds) {
										// 		if (res.ds[m].FlowType != 1) {
										// 			var z = 0;
										// 			for (var n in that.readArray) {
										// 				if (res.ds[m].Approver == that.readArray[n].LogCount) {
										// 					z = 1;
										// 				}
										// 			}
										// 			if (z == 0) {
										// 				unReadArray.push(res.ds[m])
										// 			}
										// 		}

										// 	}
										// 	that.unReadArray = unReadArray;

										// 	if (y == 1) {
										// 		APP.ajax('insertReadReview', { Ck_ReviewID: that.form.id });

										// 		var x = 0;
										// 		for (var i in res1.ds) {
										// 			if (res1.ds[i].UserID == that.userData.UserID) {
										// 				x = 1;
										// 			}
										// 		}
										// 		if (x == 0) {
										// 			var obj = {
										// 				Ck_ReviewID: that.form.id,
										// 				ApplyTotalNum: p1,
										// 				ReadTotalNum: res1.ds.length + 1
										// 			}
										// 			APP.ajax('updateCkReviewNum', obj, function (res) {
										// 				api.sendEvent({
										// 					name: 'refreshList'
										// 				});
										// 			})
										// 		}
										// 	}

										// })


									}



									that.approvalList = approvalList;

								})
							}
						} else {
							layer.open({
								content: '记录已删除',
								skin: 'msg',
								time: 2,
								end: function () {
									api.closeWin()
								}
							});
						}





					})
				},
				selectApproval: function () {
					var that = this;
					// that.showAction = true;
					that.getApprovalProcess(that.approvalActions[0].APFlowID)
				},

				confirmProcedureAction: function (action, index) {
					var that = this;
					that.form.procedurename = action.name;
				},
				openBaseScreen: function (str) {
					var that = this;
					var obj;
					if (str == '产品') {
						obj = {

							allowClear: false,
							cmd: 'getCkProductList',
							type: str,
							// localSearch:{
							// 	showText:'',		//查询结果显示的字段
							// 	searchBy:['']		//按那些字段进行搜索
							// },
							serverSearch: {
								isPaging: true,		//是否分页
								searchKey: 'ProductName',		//搜索关键词，应包含在param中
								showText: 'ProductName',		//查询结果显示的字段
								pageIndexStr: 'pageIndex'		//分页页码字段，应包含在param中
							},
							param: {
								pageIndex: 1,
								ProductName: ''
							}

						}
					}
					if (str == '人员') {
						obj = {

							allowClear: false,
							cmd: 'getCkUserList',
							type: str,
							localSearch: {
								showText: 'UserName',		//查询结果显示的字段
								searchBy: ['UserName']		//按那些字段进行搜索
							},
							param: {

							}

						}
					}
					api.openWin({
						name: 'baseScreen',
						url: 'tool/baseScreen.html',
						reload: true,
						slidBackEnabled: false,
						allowEdit: true,
						pageParam: obj
					})
				},
				getStrConfigData: function () {
					var that = this;

					//生成审批流字符串
					var childNodeList = null;
					for (var i = that.approvalProcessList.length - 1; i >= 0; i--) {
						if (that.approvalProcessList[i].checked) {
							that.approvalProcessList[i].data.childNode = JSON.parse(JSON.stringify(childNodeList));
							childNodeList = that.approvalProcessList[i].data;
							var userList = [];
							for (var j in that.approvalProcessList[i].node) {
								if (!that.approvalProcessList[i].node[j].unJoin) {
									userList.push(that.approvalProcessList[i].node[j])
								}
							}
							childNodeList.nodeUserList = userList;
						}

					}
					var newApprovalConfigdata = JSON.parse(JSON.stringify(approvalConfigdata));
					newApprovalConfigdata.nodeConfig.childNode = childNodeList;
					return JSON.stringify(newApprovalConfigdata)

				},
				savePage: function (state) {
					var that = this;
					if (!that.form.pid) {
						layer.open({
							content: '请选择产品',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (!that.form.procedurename) {
						layer.open({
							content: '请选择工序',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (!that.form.reason) {
						layer.open({
							content: '请输入不良原因',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (!that.form.personid) {
						layer.open({
							content: '请选择申请人',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					if (!that.timeout) {
						layer.open({
							content: '请输入超时时间',
							skin: 'msg',
							time: 2
						});
						return false;
					}
					var obj = {
						Ck_ReviewID: that.form.id,
						Program: that.form.project,
						BillNO: that.form.code,
						UserID: that.form.personid,
						ProductID: that.form.pid,
						NgCause: that.form.reason,
						FRemarks: that.form.remark,
						ClassID: that.form.persondepartid,
						APFlowID: 0,
						P_Timeout: that.timeout,
						Appearance: that.form.appearance,
						Size: that.form.size,
						Performance: that.form.performance,
						Others: that.form.others,
						Imgs: that.form.imgArray.join(),
						ModuleType: that.form.procedurename,
						NGType: that.form.badtype,
						IsReworkDepart: that.form.isReworkDepart
					}
					that.ifConfirm = true;
					if (that.form.id) {
						APP.ajax('updateApproveReview', obj, function (res) {
							that.ifConfirm = false;
							layer.open({
								content: '修改成功',
								skin: 'msg',
								time: 2
							});
						})
					} else {
						APP.ajax('addReviewApprove', obj, function (res) {
							that.ifConfirm = false;
							that.form.id = res.ds[0].Ck_ReviewID;

							that.$dialog.alert({
								title: '提示',
								message: '单据提交送审成功，请耐心等待相关人员确认',
							}).then(function () {
								api.closeWin();
							});

						})
					}

				},

				initiateApproval: function (index, content) {
					var that = this;
					if (that.form.id) {
						if (that.isExamine == 1) {
							var obj = {
								TableName: 'Ck_Review',
								Ck_ReviewID: that.form.id,
								// ApprovalID: that.selectApprovalData ? that.selectApprovalData.APFlowID : 0,
								approveType: index,
								Explain: content,
								approveStr: that.getStrConfigData()
							}
							that.ifConfirm = true;
							APP.ajax('bgApprove2', obj, function (res) {
								that.ifConfirm = false;
								if (res.ds.length && res.ds[0].status && res.ds[0].status == 500) {
									layer.open({
										content: res.ds[0].msg,
										skin: 'msg',
										time: 2
									});
								} else {
									if (index == 1) {
										layer.open({
											content: '该单据已拒绝审批',
											skin: 'msg',
											time: 2
										});
									} else {

										if (APP.getUserInfo().UserID == 18 || APP.getUserInfo().UserID == 19) {
											that.isExamine = 2;
											that.initiateApproval(index, content);
											return;
										} else {
											layer.open({
												content: '审批提交成功',
												skin: 'msg',
												time: 2
											});
										}
									}
									that.isSubmit = true;
									that.finalResult = 0;
									that.approvalAgain = false;
									that.checkIsShowButton();
									that.initPageData();

									api.sendEvent({
										name: 'refreshList'
									});
								}

							})
						} else if (that.isExamine == 2) {

							function submitApproaval(id) {
								var obj = {
									TableName: 'Ck_Review',
									Ck_ReviewID: that.form.id,
									ApprovalID: id,
									approveType: index,
									Explain: content
								}
								that.ifConfirm = true;
								APP.ajax('bgApprove', obj, function (res) {
									that.ifConfirm = false;
									if (res.ds.length && res.ds[0].status && res.ds[0].status == 500) {
										layer.open({
											content: res.ds[0].msg,
											skin: 'msg',
											time: 2
										});
									} else {
										if (index == 1) {
											layer.open({
												content: '该单据已拒绝审批',
												skin: 'msg',
												time: 2
											});
										} else {
											layer.open({
												content: '审批提交成功',
												skin: 'msg',
												time: 2
											});
										}
										that.isSubmit = true;
										that.finalResult = 0;
										that.approvalAgain = false;
										that.checkIsShowButton();
										that.initPageData();

										api.sendEvent({
											name: 'refreshList'
										});
									}

								})
							}

							if (index == 1) {
								submitApproaval(0);
							} else {
								var iobj = {
									BillName: 'approvalPage1_' + new Date().getTime(),
									AppFormName: 'approvalPage1',
									AppConfigStr: that.getStrConfigData()
								}
								APP.ajax('insertApproveConfig', iobj, function (res) {
									var id = res.ds[0].APFlowID;

									that.post('delete SYS_BillAPFlowDe where APFlowID=' + id, {}, function () {
										try {
											var appConfigObj = JSON.parse(that.getStrConfigData());
											var aPUserIDs = [], classIDs = []
											for (var q = 0; q < appConfigObj.flowPermission.length; q++) {
												if (appConfigObj.flowPermission[q].type == 1) {
													aPUserIDs.push(appConfigObj.flowPermission[q].targetId);
												} else if (appConfigObj.flowPermission[q].type == 3) {
													classIDs.push(appConfigObj.flowPermission[q].targetId);
												}
											}
											//保存发起人
											var sql = 'insert into SYS_BillAPFlowDe(APFlowID,APFlowNO,APUserID,RoleIDs,JobLevel,ClassIDs,SignedWay,FlowType,FlowName) values(@APFlowID,@APFlowNO,@APUserID,@RoleIDs,@JobLevel,@ClassIDs,@SignedWay,@FlowType,@FlowName)';
											that.post(sql, {
												APFlowID: id,
												APFlowNO: '0',
												APUserID: aPUserIDs.join(','),
												RoleIDs: '',
												JobLevel: '0',
												ClassIDs: classIDs.join(','),
												SignedWay: '0',
												FlowType: '0',
												FlowName: ''
											}, function () { });
											//保存各级审批及抄送人
											var saveApproveFunc = function (node, flowNo) {
												var caPUserIDs = [], cclassIDs = [], croleIDs = []
												var Joblevel = 0;
												var flowType = 0;
												var signedWay = 0;
												for (var k = 0; k < node.nodeUserList.length; k++) {
													if (node.nodeUserList[k].type == 1) {
														caPUserIDs.push(node.nodeUserList[k].targetId);
													} else if (node.nodeUserList[k].type == 3) {
														cclassIDs.push(node.nodeUserList[k].targetId);
													} else if (node.nodeUserList[k].type == 2) {
														croleIDs.push(node.nodeUserList[k].targetId);
													}
												}
												if (node.settype == 7) {
													Joblevel = node.examineEndDirectorLevel;
												}
												if (node.type == 1) {
													flowType = 0;
												} else {
													flowType = 1;
												}
												if (node.examineMode == 1) {
													signedWay = 0;
												} else {
													signedWay = 1;
												}
												var flowName = node.nodeName;

												that.post(sql, {
													APFlowID: id,
													APFlowNO: flowNo,
													APUserID: caPUserIDs.join(','),
													RoleIDs: croleIDs.join(','),
													JobLevel: Joblevel,
													ClassIDs: cclassIDs.join(','),
													SignedWay: signedWay,
													FlowType: flowType,
													FlowName: flowName
												}, function () { });
												flowNo++
												saveApproveFunc(node.childNode, flowNo);

											}
											saveApproveFunc(appConfigObj.nodeConfig.childNode, 1);
										} catch (e) {
											// alert(e)
											submitApproaval(id);
										}
									});


								})
							}



						}




					}
				},
				initiateApprovalAgain: function () {
					var that = this;
					if (that.approvalAgain) {
						that.savePage(true);
					} else {
						that.approvalAgain = true;
						that.getApprovalProcess(that.approvalID);
					}

				},
				dealApproval: function (index) {
					var that = this;
					var status = false;
					if (that.status == 1) {
						var nowLevel = that.approvalList[that.approvalList.length - 1].level;
						if (that.approvalList[that.approvalList.length - 1].approvalNodeList[nowLevel].department.indexOf('经理') == -1) {
							status = true;
						}
					}
					api.openWin({
						name: 'approvalDeal',
						url: 'approvalDeal.html',
						reload: true,
						slidBackEnabled: false,
						allowEdit: true,
						pageParam: {
							approvalID: that.approvalID,
							index: index,
							status: status,
							showPhone: false,
							reWork: false
						}
					})





				},
				submitApproval: function (index, content, imgArray, reworkDepart) {
					var that = this;
					var obj = {
						TableName: 'SYS_GeneralApproval',
						ApprovalSort: that.approvalList[that.approvalList.length - 1].level + 1,
						ApprovalID: that.approvalID,
						ApprovalContent: (that.status == 1 && index == 1 && !content) ? '同意' : content,
						Approve: index,
						KeyID: that.form.id,
						Imgs: imgArray ? imgArray.join() : ''
					}
					APP.ajax('Ck_ApprovalForm', obj, function (res) {
						that.ifConfirm = false;
						if (res.ds.length && res.ds[0].status && res.ds[0].status == 500) {
							layer.open({
								content: res.ds[0].msg,
								skin: 'msg',
								time: 2
							});
						} else {
							if (reworkDepart) {
								var obj = {
									Ck_ReviewID: that.form.id,
									reworkDepart: reworkDepart
								}
								APP.ajax('updateReworkDepart', obj, function (res) {
									layer.open({
										content: '审批成功',
										skin: 'msg',
										time: 2
									});
									that.checkIsShowButton();
									that.initPageData();

									api.sendEvent({
										name: 'refreshList'
									});
								})
							} else {
								layer.open({
									content: '审批成功',
									skin: 'msg',
									time: 2
								});
								that.checkIsShowButton();
								that.initPageData();

								api.sendEvent({
									name: 'refreshList'
								});
							}

						}

					})
				},
				startApproval: function (index, content) {
					var that = this;
					that.initiateApproval(index == 2 ? 1 : 0, content);
				},
				addRemark: function () {
					var that = this;
					if (that.editRemark) {
						api.openWin({
							name: 'editRemark',
							url: 'editRemark.html',
							reload: true,
							slidBackEnabled: false,
							allowEdit: true,
							pageParam: {
								img: that.form.memoImg
							}
						})
					}

				},

				//计算分组请购汇总金额环比
				calcByGrp(groupType) {
					var result = [];	//结果
					var thisM = [];	//本月
					var lastM = [];	//上月

					if (groupType == 'byBM') {
						thisM = vm.form.list2;
						lastM = vm.form.list4;
						for (var i in thisM) {
							var x = 0;
							var obj;
							for (var j in lastM) {
								if (thisM[i].ClassName == lastM[j].ClassName) {
									x = 1;
									obj = vm.calcHB(thisM[i].ClassName, thisM[i].money, lastM[j].money);
									result.push(obj);
								}
							}
							if (!x) {
								obj = vm.calcHB(thisM[i].ClassName, thisM[i].money, 0);	//上月没有则金额为0
								result.push(obj);
							}
						}
					} else if (groupType == 'byWL') {
						thisM = vm.form.list3;
						lastM = vm.form.list5;
						for (var i in thisM) {
							var x = 0;
							var obj;
							for (var j in lastM) {
								if (thisM[i].CinvCName == lastM[j].CinvCName) {
									x = 1;
									obj = vm.calcHB(thisM[i].CinvCName, thisM[i].money, lastM[j].money);
									result.push(obj);
								}
							}
							if (!x) {
								obj = vm.calcHB(thisM[i].CinvCName, thisM[i].money, 0);	//上月没有则金额为0
								result.push(obj);
							}
						}

					} else if (groupType == 'byTotal') {
						var obj = vm.calcHB('', vm.form.totalMoney, vm.form.lastMonFee)
						result.push(obj);
					}
					return result;
				},
				//计算环比结果
				calcHB(tagName, thisMonMoney, lastMonMoney) {
					var incFlag = 0;	//是否上升 1上升 -1下降 0不变
					var rate = 0;	//上升/下降率
					var signFlag = '';	//正负号
					var tailFlag = '%';//百分号

					if ((Number(thisMonMoney) > Number(lastMonMoney)) && Number(lastMonMoney) > 0) {
						incFlag = 1;
						signFlag = '↑';
						rate = ((Number(thisMonMoney) - Number(lastMonMoney)) * 100) / Number(lastMonMoney);
					} else if ((Number(thisMonMoney) < Number(lastMonMoney)) && Number(lastMonMoney) > 0) {
						incFlag = -1;
						signFlag = '↓';
						rate = ((Number(lastMonMoney) - Number(thisMonMoney)) * 100) / Number(lastMonMoney);
					} else if (Number(lastMonMoney) == 0) {
						incFlag = 1;
						rate = '-';
					}
					//环比计算结果
					var hbResultObj = {
						tagName: tagName,
						incFlag: incFlag,
						thisMonMoney: Number(thisMonMoney),
						lastMonMoney: Number(lastMonMoney),
						rate: rate == '-' ? '-' : (signFlag + (rate.toFixed(2)) + tailFlag)
					};
					return hbResultObj;
				},
				onClickLeft: function () {
					var that = this;
					api.closeWin();

				}
			}
		})
	};
</script>

</html>